package com.ctshk.rpc.payment.enums;

import com.ctshk.common.constant.SystemConstants;
import com.ctshk.common.enums.PayRefundMethod;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @BelongsProject: ctshk-cloud
 * @BelongsPackage: com.ctshk.rpc.payment.enums
 * @Author: hef
 * @CreateTime: 2021-04-20 17:35
 * @Description: 支付方式
 */
@Getter
@AllArgsConstructor
public enum PaymentMethod {
    ALI_PAY_HK_H5(1, SystemConstants.PAY_TYPE_ALI, "HK支付宝_H5", PayRefundMethod.ALI_PAY_HK_H5.getId()),
    ALI_PAY_CH_H5(2, SystemConstants.PAY_TYPE_ALI, "CH支付宝_H5", PayRefundMethod.ALI_PAY_CH_H5.getId()),
    ALI_PAY_HK_PC(3, SystemConstants.PAY_TYPE_ALI, "HK支付宝_PC", PayRefundMethod.ALI_PAY_HK_PC.getId()),
    ALI_PAY_CH_PC(4, SystemConstants.PAY_TYPE_ALI, "CH支付宝_PC", PayRefundMethod.ALI_PAY_CH_PC.getId()),
    ALI_PAY_HK_APP(5, SystemConstants.PAY_TYPE_ALI, "HK支付宝_APP", PayRefundMethod.ALI_PAY_HK_APP.getId()),
    ALI_PAY_CH_APP(6, SystemConstants.PAY_TYPE_ALI, "CH支付宝_APP", PayRefundMethod.ALI_PAY_CH_APP.getId()),
    WE_CHAT_PAY_NATIVE(7, SystemConstants.PAY_TYPE_WECHAT, "微信支付_NATIVE", PayRefundMethod.WE_CHAT_PAY_NATIVE.getId()),
    WE_CHAT_PAY_APP(8, SystemConstants.PAY_TYPE_WECHAT, "微信支付_APP", PayRefundMethod.WE_CHAT_PAY_APP.getId()),
    UNIONPAY_ONLINE_PAYMENT_APP(9, SystemConstants.PAY_TYPE_UNIPAY, "银联在线支付-APP", PayRefundMethod.UNIONPAY_ONLINE_PAYMENT_APP.getId()),
    UNIONPAY_ONLINE_PAYMENT_WEB(10, SystemConstants.PAY_TYPE_UNIPAY, "银联在线支付-WEB", PayRefundMethod.UNIONPAY_ONLINE_PAYMENT_WEB.getId()),
    UNIONPAY_ONLINE_PAYMENT_WAP(11, SystemConstants.PAY_TYPE_UNIPAY, "银联在线支付-WAP", PayRefundMethod.UNIONPAY_ONLINE_PAYMENT_WAP.getId()),
    VISA_MASTERCARD_HOSTED(12, SystemConstants.PAY_TYPE_VISA_MASTER, "Visa/MasterCard-托管", PayRefundMethod.VISA_MASTERCARD_HOSTED.getId()),
    WE_CHAT_PAY_H5(13, SystemConstants.PAY_TYPE_WECHAT, "微信支付_H5", PayRefundMethod.WE_CHAT_PAY_APP.getId()), // 第三方暂不支持
    ;
    private Integer code;
    private Integer type; //1:支付宝,2:微信,3:银联支付,4:Visa/MasterCard
    private String name;
    private Long payRefundMethodId; // 枚举PayRefundMethod的Id


    /**
     * 获取枚举
     *
     * @param code
     * @return
     */
    public static PaymentMethod getByCode(Integer code) {
        PaymentMethod paymentMethod = Arrays.stream(PaymentMethod.values())
                .filter(enums -> enums.getCode().equals(code)).findFirst().orElse(null);
        return paymentMethod;
    }

    public static PaymentMethod getByPayRefundMethodId(Long id) {
        PaymentMethod paymentMethod = Arrays.stream(PaymentMethod.values())
                .filter(enums -> {
                            System.out.println(enums.getPayRefundMethodId());
                            return enums.getPayRefundMethodId().equals(id);
                        }
                ).findFirst().orElse(null);
        return paymentMethod;
    }

    public static boolean isStream(Integer code) {
        return Arrays.asList().contains(code);
    }
}
